﻿var backgroundPage = chrome.extension.getBackgroundPage();

function addLoadEvent(elm, evType, fn, useCapture) {
    if (elm) {
        if (elm.addEventListener) {
            elm.addEventListener(evType, fn, useCapture);
            return true;
        } else if (elm.attachEvent) {
            var r = elm.attachEvent("on" + evType, fn);
            return r;
        } else {
        }
    }
}

addLoadEvent(window, 'beforeunload', function () {
    backgroundPage.ws.tryStop();
});

addLoadEvent(window, 'keydown', function (ev) {
    if (ev.keyCode == 116) {
        ev.returnValue = false;
    } if (ev.ctrlKey == true && ev.keyCode == 82) {
        ev.returnValue = false;
    }
});

backgroundPage.ws.quitStop();